import subprocess
import datetime

# List your script filenames
scripts = ['3_estimate_embeddings_main.py', 
           '3a_estimate_embeddings_alternative.py', 
           '3b_estimate_embeddings_singlestatement.py']

# Name of log file
log_file = 'python_log.txt'

# Start logging
with open(log_file, 'w') as f:
    f.write("Python Script Execution Log\n")
    f.write(f"Started at: {datetime.datetime.now()}\n\n")

    for script in scripts:
        f.write(f"Running: {script}\n")
        try:
            # Run the script using subprocess and capture output
            result = subprocess.run(['python', script], capture_output=True, text=True, check=True)
            f.write(f"SUCCESS: {script} completed at {datetime.datetime.now()}\n")
            f.write(f"Output:\n{result.stdout}\n\n")
        except subprocess.CalledProcessError as e:
            f.write(f"ERROR: {script} failed at {datetime.datetime.now()}\n")
            f.write(f"Error Output:\n{e.stderr}\n\n")

    f.write(f"Finished at: {datetime.datetime.now()}\n")



